//
//  HNSH_ApplyRefundTypeCell.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/3/1.
//

#import "HNSH_ApplyRefundTypeCell.h"

@interface HNSH_ApplyRefundTypeCell ()
/** */
@property (nonatomic, strong)UIView * bgView;
/** */
@property (nonatomic, strong)UITextField * textField;
/** */
@property (nonatomic, strong)UIButton * chooseBtn;
@end


@implementation HNSH_ApplyRefundTypeCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor appBGColor];
        [self configUI];
    }
    return self;
}

- (void)setPlaceholder:(NSString *)placeholder {
    _placeholder = placeholder;
    self.textField.placeholder = placeholder;
    NSMutableAttributedString *placeholderString = [[NSMutableAttributedString alloc] initWithString:self.textField.placeholder];
    [placeholderString addAttribute:NSForegroundColorAttributeName
                            value:[UIColor appGrayLabelColor]
                            range:NSMakeRange(0, self.textField.placeholder.length)];
    [placeholderString addAttribute:NSFontAttributeName
                            value:[UIFont systemFontOfSize:14]
                            range:NSMakeRange(0, self.textField.placeholder.length)];
    self.textField.attributedPlaceholder = placeholderString;
}

- (void)configUI {
    [self addAllViews];
    [self addAllLayout];
}

//MARK: Cycle Methods
- (void)addAllViews{
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.textField];
    [self.bgView addSubview:self.chooseBtn];
}

- (void)addAllLayout{
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.top.height.mas_equalTo(self.contentView);
    }];
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.top.height.mas_equalTo(self.bgView);
    }];
    [self.chooseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(0);
        make.top.height.mas_equalTo(self.bgView);
        make.width.mas_equalTo(50);
    }];
}

//MARK:
- (void)chooseBtnAction{
    
}

//MARK: Setter Methods
- (void)setDic:(NSDictionary *)dic{
    _dic = dic;
    
    self.textField.placeholder = dic[@"place"];
    NSString * content = dic[@"content"];
    if (content.length) {
        self.textField.text = content;
    } else {
        self.textField.text = nil;
    }
    BOOL isRefund = [dic[@"isRefund"] boolValue];
    if (isRefund) {
        self.chooseBtn.hidden = YES;
    } else {
        self.chooseBtn.hidden = NO;
    }
}

//MARK: Getter Methods
- (UIView *)bgView{
    if (!_bgView) {
        _bgView = [UIImageView new];
        _bgView.backgroundColor = [UIColor whiteColor];
        _bgView.layer.cornerRadius = 4;
        _bgView.layer.masksToBounds = YES;
    }
    return _bgView;
}

- (UITextField *)textField{
    if (!_textField) {
        _textField = [UITextField new];
        _textField.backgroundColor = [UIColor clearColor];
        _textField.textColor = [UIColor appBlackLabelColor];
        _textField.font = [UIFont systemFontOfSize:16];
    }
    return _textField;
}

- (UIButton *)chooseBtn{
    if (!_chooseBtn) {
        _chooseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_chooseBtn setImage:[UIImage imageNamed:@"mine_order_apply_refund_show"] forState:UIControlStateNormal];
        [_chooseBtn addTarget:self action:@selector(chooseBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _chooseBtn;
}

@end
